// @algorithm @lc id=100333 lang=cpp
// @title er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof

#include "algm/algm.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
    // @test([3,1,4,null,2], 1)=4
public:
    int kthLargest(TreeNode *root, int k) {
        vector<int> vec;
        postOrder(root, vec);
        int n = vec.size();
        return vec[n - k];
    }

    void postOrder(TreeNode *root, vector<int> &vec) {
        if (root == nullptr) {
            return;
        }
        postOrder(root->left, vec);
        vec.push_back(root->val);
        postOrder(root->right, vec);
    }
};